package com.yanqu.road.server.cmd.unionwar;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.unionwar.UnionWarActivityServerProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.unionwar.CrossUnionWarActivityMgr;
import com.yanqu.road.server.manager.unionwar.CrossUnionWarMgr;
import com.yanqu.road.server.manager.unionwar.CrossUnionWarRankMgr;
import com.yanqu.road.server.manger.TempCommonMgr;
import com.yanqu.road.server.protocol.CrossProtocol;

@Cmd(code = CrossProtocol.C_CROSS_UNION_WAR_HELPER_CODE, desc = "商会战活动系统通知")
public class CrossUnionWarHelpCodeCmd extends CrossUnionCommand {

    int activityId;
    int type;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        UnionWarActivityServerProto.UnionWarActivityHelpCode msg = UnionWarActivityServerProto.UnionWarActivityHelpCode.parseFrom(packet.getBytes());
        activityId = msg.getActivityId();
        type = msg.getType();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        if (type == 1) {
            CrossUnionWarActivityMgr.reloadConfig(activityId);
        } else if (type == 2) {
            CrossUnionWarMgr.repair(activityId);
        } else if(type == 3){
            TempCommonMgr.reloadCommonData();
        } else if(type == 5){
            //修复冠军榜单
            ActivityInfo activityInfo = CrossUnionWarActivityMgr.getOpenActivity(activityId);
            if(activityInfo != null){
                log.info("start repair activity {} addChampion", activityId);
                CrossUnionWarRankMgr.addChampion(activityInfo);
            }
        }
    }

    @Override
    public void sendData() {

    }
}
